import tkinter as tk
import pymysql


# 商品表的查询
def select_sp():
    # 建立连接
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    sql = "select * from 商品表 where 商品编号=%s"
    try:
        cursor.execute(sql, (v1.get()))
        results = cursor.fetchall()
        tk.messagebox.showinfo(title='商品表', message=results)
    except:
        return


# 条件查找商品界面
def select_sp_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="查找商品信息", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入商品编号：").grid(row=1, column=0, padx=20)
    g14 = tk.StringVar()
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    button = tk.Button(window_function, text="查找", command=select_sp).place(relx=0.3, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.5, rely=0.5)
    window_function.mainloop()


# 员工表的查询
def select_yg():
    # 建立连接
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    sql = "select * from 员工表 where 员工编号=%s"
    try:
        cursor.execute(sql, (v1.get()))
        results = cursor.fetchall()
        tk.messagebox.showinfo(title='员工表', message=results)
    except:
        return


# 条件查找商品界面
def select_yg_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="查找员工信息", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入员工编号：").grid(row=1, column=0, padx=20)
    g14 = tk.StringVar()
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    button = tk.Button(window_function, text="查找", command=select_yg).place(relx=0.3, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.5, rely=0.5)
    window_function.mainloop()


# 供应商表的查询
def select_gys():
    # 建立连接
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    sql = "select * from 供应商表 where 供应商编号=%s"
    try:
        cursor.execute(sql, (v1.get()))
        results = cursor.fetchall()
        tk.messagebox.showinfo(title='供应商表', message=results)
    except:
        return


# 条件查找商品界面
def select_gys_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="查找供应商信息", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入供应商编号：").grid(row=1, column=0, padx=20)
    g14 = tk.StringVar()
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    button = tk.Button(window_function, text="查找", command=select_gys).place(relx=0.3, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.5, rely=0.5)
    window_function.mainloop()


# 采购主表的查询
def select_cg():
    # 建立连接
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    sql = "select * from 采购主表 where 采购清单号=%s"
    try:
        cursor.execute(sql, (v1.get()))
        results = cursor.fetchall()
        tk.messagebox.showinfo(title='采购主表', message=results)
    except:
        return


# 条件查找商品界面
def select_cg_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="查找采购信息", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入采购清单号：").grid(row=1, column=0, padx=20)
    g14 = tk.StringVar()
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    button = tk.Button(window_function, text="查找", command=select_cg).place(relx=0.3, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.5, rely=0.5)
    window_function.mainloop()


# 采购明细表的查询
def select_mx():
    # 建立连接
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    sql = "select * from 采购明细表 where 采购明细号=%s"
    try:
        cursor.execute(sql, (v1.get()))
        results = cursor.fetchall()
        tk.messagebox.showinfo(title='采购明细表', message=results)
    except:
        return


# 条件查找商品界面
def select_mx_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    window_function.geometry('400x500')
    tk.Label(window_function, text="查找采购明细", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入采购明细号：").grid(row=1, column=0, padx=20)
    g14 = tk.StringVar()
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    button = tk.Button(window_function, text="查找", command=select_mx).place(relx=0.3, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_mainpage).place(relx=0.5, rely=0.5)
    window_function.mainloop()


def to_mainpage():
    window.destroy()
    mainpage()


# 主界面
def mainpage():
    global window
    window = tk.Tk()
    window.title("超市管理系统")
    